<%-- 
    Document   : mantevisitador
    Created on : 08/15/2013, 10:23:34 PM
    Author     : grakeskull
--%>

<%@page import="edu.capex.farmacus.Manager.SupervisoresManager"%>
<%@page import="edu.capex.farmacus.encapsulates.Supervisores"%>
<%@page import="edu.capex.farmacus.encapsulates.Visitadores"%>
<%@page import="edu.capex.farmacus.Manager.VisitadoresManager"%>
<%@page contentType="text/html" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>

<%
    Visitadores visitadorAMod = null;

    if (request.getParameter("nombre") != null && request.getParameter("cedula") != null
            && request.getParameter("telefono") != null && request.getParameter("supervisor") != null && request.getParameter("correo") != null
            && request.getParameter("id") != null && request.getParameter("moid") == null) {

        //Visitadores visitador = new Visitadores(new Integer(request.getParameter("id")));
        Visitadores visitador = new VisitadoresManager().findVisitadores(new Integer(request.getParameter("id")));
        boolean existe = false;

        if (visitador == null) {
            visitador = new Visitadores();
        } else {
            existe = true;
        }

        visitador.setId(new Integer(request.getParameter("id")));
        visitador.setCedula(request.getParameter("cedula"));
        visitador.setCorreovisitador(request.getParameter("correo"));
        visitador.setTelefono(request.getParameter("telefono"));
        visitador.setNombre(request.getParameter("nombre"));
        visitador.setSupervisor(new Integer(request.getParameter("supervisor")));

        if (existe) {
            new VisitadoresManager().edit(visitador);
        } else {
            new VisitadoresManager().create(visitador);
        }

    } else if (request.getParameter("moid") != null && request.getParameter("modificar").equalsIgnoreCase("modificar")) {
        visitadorAMod = new VisitadoresManager().findVisitadores(new Integer(request.getParameter("moid")));
    } else if (request.getParameter("reid") != null && request.getParameter("eliminar").equalsIgnoreCase("eliminar")) {
        new VisitadoresManager().destroy(new Integer(request.getParameter("reid")));
    }

%>
<html>
    <head>
        <%@include file="/resources/header.jsp" %>
        <script src="../js/bsa.js"></script>
    </head>
    <%@include file="/resources/header1.jsp" %>
    <body class="preview" data-spy="scroll" data-target=".subnav" data-offset="80">

        <div class="container">
           
            <section id="typography">
               

                <%@include file="/admin/supervisores/menuadm.jsp" %>

                <h2>Mantenimiento Visitador </h2>

                <section id="forms">

                    <form class="form-horizontal well" method="POST" id="myForm">
                        <fieldset>

                            <%if (visitadorAMod != null) {%>

                            <input type="hidden" name="id" value="<%=visitadorAMod.getId()%>"/>
                            <div class="control-group">
                                <label class="control-label" for="input01">Nombre</label>
                                <div class="controls">
                                    <input type="text" class="input-xlarge" data-required id="input01" name="nombre" value="<%=visitadorAMod.getNombre()%>"/>
                                </div>
                            </div>

                            <div class="control-group">
                                <label class="control-label" for="input01">cedula</label>
                                <div class="controls">
                                    <input type="text" class="input-xlarge" data-required id="input01" name="cedula" value="<%=visitadorAMod.getCedula()%>"/>
                                </div>  
                            </div>

                            <div class="control-group">
                                <label class="control-label" for="input01">Telefono</label>
                                <div class="controls">
                                    <input type="text" class="input-xlarge" data-required id="input01" name="telefono" value="<%=visitadorAMod.getTelefono()%>"/>
                                </div>
                            </div>

                            <div class="control-group">
                                <label class="control-label" for="input01">Supervisor</label>
                                <div class="controls">
                                    <select name="supervisor" class="input-xlarge">
                                        <%
                                            for (Supervisores temp : new SupervisoresManager().findSupervisoresEntities()) {
                                                if (visitadorAMod.getSupervisor() == temp.getIdsupervisores()) {
                                        %>
                                        <option value="<%=temp.getIdsupervisores()%>" selected><%=temp.getNombresupervisores()%></option>
                                        <%} else {%>
                                        <option value="<%=temp.getIdsupervisores()%>"><%=temp.getNombresupervisores()%></option>
                                        <%}%>
                                        <%}%>
                                    </select>
                                </div>
                            </div>

                            <div class="control-group">
                                <label class="control-label" for="input01">Correo</label>
                                <div class="controls">
                                    <input type="text" class="input-xlarge" data-required id="input01" name="correo" value="<%=visitadorAMod.getCorreovisitador()%>"/>
                                </div>
                            </div>



                            <div class="form-actions">
                                <button type="submit" class="btn btn-primary" name="modificar">Modificar</button>
                                <button type="reset" class="btn">Cancelar</button>
                            </div>
                            <%} else {%>
                            <input type="hidden" name="id" value="<%=new VisitadoresManager().nextId()%>"/>
                            <div class="control-group">
                                <label class="control-label" for="input01">Nombre</label>
                                <div class="controls">
                                    <input type="text" class="input-xlarge" data-required id="input01" name="nombre">
                                </div>
                            </div>

                            <div class="control-group">
                                <label class="control-label" for="input01">cedula</label>
                                <div class="controls">
                                    <input type="text" class="input-xlarge" data-required id="input01" name="cedula">
                                </div>
                            </div>

                            <div class="control-group">
                                <label class="control-label" for="input01">Telefono</label>
                                <div class="controls">
                                    <input type="text" class="input-xlarge" data-required id="input01" name="telefono">
                                </div>
                            </div>

                            <div class="control-group">
                                <label class="control-label" for="input01">Supervisor</label>   
                                <div class="controls">
                                    <select name="supervisor" class="input-xlarge">
                                        <%
                                            for (Supervisores temp : new SupervisoresManager().findSupervisoresEntities()) {
                                        %>
                                        <option value="<%=temp.getIdsupervisores()%>"><%=temp.getNombresupervisores()%></option>
                                        <%}%>
                                    </select>
                                </div>
                            </div>

                            <div class="control-group">
                                <label class="control-label" for="input01">Correo</label>
                                <div class="controls">
                                    <input type="text" class="input-xlarge" data-required id="input01" name="correo">
                                </div>
                            </div>


                            <div class="form-actions">
                                <button type="submit" class="btn btn-primary" name="guardar">Agregar</button>
                                <button type="reset" class="btn">Cancelar</button>
                            </div>
                            <%}%>
                        </fieldset>
                    </form>
                    <table id="myTable" class="table table-bordered table-striped">
                        <thead>
                            <tr>
                                <th>
                                    Nombre
                                </th>
                                <th>
                                    Cedula
                                </th>
                                <th>
                                    Telefono
                                </th>
                                <th>
                                    Supervisor
                                </th>
                                <th>
                                    Correo
                                </th>
                                <th filter="false">
                                    Modificar
                                </th>
                                <th filter="false">
                                    Eliminar
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                            <%
                                for (Visitadores temp : new VisitadoresManager().findVisitadoresEntities()) {
                            %>
                            <tr>
                                <td>
                                    <%=temp.getNombre()%>
                                </td>
                                <td>
                                    <%=temp.getCedula()%>
                                </td>
                                <td>
                                    <%=temp.getTelefono()%>
                                </td>
                                <td>
                                    <%=new SupervisoresManager().findSupervisores(temp.getSupervisor()).getNombresupervisores()%>
                                </td>
                                <td>
                                    <%=temp.getCorreovisitador()%>
                                </td>
                                <td>
                                    <form action="#" method="POST">
                                        <center>
                                            <input type="hidden" name="moid" value="<%=temp.getId()%>"/>
                                            <input type="submit" name="modificar" value="Modificar" class="btn"/>
                                        </center>
                                    </form>
                                </td>
                                <td>
                                    <form action="#" method="POST">
                                        <center>
                                            <input type="hidden" name="reid" value="<%=temp.getId()%>"/>
                                            <input type="submit" name="eliminar" value="Eliminar" class="btn"/>
                                        </center>
                                    </form>
                                </td>
                            </tr>
                            <%}%>
                        </tbody>
                    </table> 

                    <%@include file="/resources/footer1.jsp" %>
                </section>
            </section>
        </div>
        <script type="text/javascript">
            $(document).ready(function() {
                $("#myTable").tableFilter();
                $('#myForm').validate({
                    onKeyup: true,
                    eachValidField: function() {

                        $(this).closest('div').removeClass('error').addClass('success');
                    },
                    eachInvalidField: function() {

                        $(this).closest('div').removeClass('success').addClass('error');
                    }
                });

            });
        </script>
    </body>
</html>

